package com.opc.entity;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author SEG
 */
@Data
public class PageRes<T> implements Serializable {

    private Integer pageNo;

    private Integer pageSize;

    private Integer totalPage;

    private Long totalCount;

    private List<T> rows;

    public PageRes(int pageNo, int pageSize, long totalCount, List<T> rows) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.totalPage = totalPage();
        this.rows = rows;
    }

    private Integer totalPage() {
        if (totalCount == 0 || pageSize == 0) {
            return 1;
        }
        return (int) Math.ceil((float) totalCount / pageSize);
    }
}

